
package chat.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.Provider.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import chat.single.MsgSing;
import chat.user.ChatMsg;

public class ChatMsgView extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String path = req.getContextPath();
	
	
		PrintWriter w = resp.getWriter();
		w.println("<!DOCTYPE html>");
		w.println("<html>");
			w.println("<head>");
				w.println("<meta charset='UTF-8'>");
				w.println("<title></title>");
			w.println("</head>");
			w.println("<body style='height:297px;margin: 0;'>");
				w.println("<div style='width:100%;height:100%; background-color:cornflowerblue;'>");
				ArrayList list = MsgSing.getIns().getAllMsg();
				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
				
				for (int i = 0; i < list.size(); i++) {
					ChatMsg msg = (ChatMsg) list.get(i);
					String content=msg.getContent();
					String conten1t = new String(content.getBytes("iso-8859-1"), "utf-8");
					chat.user.UserBean u = msg.getUser();
					String ct = sf.format(msg.getCreateTime());

					w.println("<br/>"+u.getName()+"   :"+conten1t+" </br>["+ct+"]");
				}
				w.println("</div>");
			w.println("</body>");
		w.println("</html>");

				w.flush();
			}
			
			
		}


